package Java7_Concurrency_Cookbook.concurrent_collection_framework.atomic_array;

import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * @author lixiangke
 * @date 2017/11/24
 */
public class Incrementer implements Runnable {
    private AtomicIntegerArray vector;

    public Incrementer(AtomicIntegerArray vector) {
        this.vector = vector;
    }

    @Override
    public void run() {
        System.out.println("Incrementer: " + vector);
        for (int i = 0; i < vector.length(); i++) {
            // 给 i 位置的元素 +1
            vector.getAndIncrement(i);
        }
    }
}
